Welcome to Ryan Lewe's Calculator Page <p>  CS 143: Project 1A
<form action="calculator.php" method="post">
Type an expression in the following box (e.g., 10.5+20*3/25):
<input type="text" name="expr" />
<input type="submit" value = "Calculate!"/>
<p>Result<p>
<?php
  $equ= $_POST["expr"];
  if(preg_match_all("/^-?(\d+(\.\d*)?|.\d+)(\ *[-|*|+]\ *-?(\d+(\.\d*)?|.\d+)|\ *\/\ *(-?\d*[1-9]\d*(\.\d*)?|-?\d*\.\d*[1-9]\d*))*$/", $equ, $matches) == 1){ //PATTERN MATCHING
    eval("\$ans= $equ;");
    echo $equ ." = " .$ans;
  } else {
    $ans = "Please check input.";
    echo $ans;
  }
?>
